let str = "";
// var shopList = [{
//     id:
// }]

window.onload = function () {
    fullTable(bookList);
}

/**
 * 根据id获取对象
 * @param id 对象id
 * @returns {HTMLElement} 返回对象列表
 */
function $(id) {
    return document.getElementById(id);
}

/**
 * 所有对象集合
 * @param array
 */
function fullTable(array) {
    let str = "";
    array.forEach(n => {
        str += `<tr>
<td><img src="${n.img}" alt="" style="width: 85px;height: 100px"></td>
<td>${n.name}</td>
<td>${n.writer}</td>
<td>${n.selling}</td>
<td><input type="button" value="查看" onclick="showDiv(${n.id})">
<input type="button" value="加入购物车" onclick="showBuyDiv(${n.id})"></td>
</tr>`;
    });
    $("data").innerHTML = str;
}

function showDiv(id) {
    $("showDiv").style.visibility = "visible";
    check(id);
}

/**
 * 查看书本详情
 */
function check(id) {
    // alert(id);
    var index = bookList.find(n => n.id == id);
    $("showBook").src = index.img;
    $("showBookName").innerHTML = "《" + index.name + "》";
    $("showBookWriter").innerHTML = index.writer;
    $("showBookContent").innerHTML = "$" + index.selling;
}

function showBuyDiv(id) {
    $("buyDiv").style.visibility = "visible";
    buyBook(id)
}


/**
 * 加入购物车
 * @param id 对象id
 */


function buyBook(id) {
    var index = bookList.find(n => n.id == id);
    str += `<tr>
<td>${index.name}</td>
<td>${index.writer}</td>
<td>${index.selling}</td>
<td>
<input type="text"></td>
<td><input type="button" onclick="deleBook()" value="删除"></td>
</tr>`;
    $("ddd").innerHTML = str;
}

/**
 * 继续购物
 * 关闭购物车
 */
function closeDiv() {
    $("buyDiv").style.visibility = "hidden";
}

function change(array) {
    // $("allMoney").innerHTML
}

function findBook(array){

}

function deleBook() {

}

function end() {

}


